//
//  EvaluationDetailTableViewController.m
//  LPTClient
//
//  Created by apple on 2018/12/8.
//  Copyright © 2018 zhaodd. All rights reserved.
//

#import "EvaluationDetailTableViewController.h"
#import "EvaluationDetailTableViewCell.h"

@interface EvaluationDetailTableViewController ()

@property (nonatomic, copy) NSArray *m_array;

@end

@implementation EvaluationDetailTableViewController



+ (instancetype)instance
{
    UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Mine" bundle:nil];
    EvaluationDetailTableViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"EvaluationDetailTableViewControllerID"];
    return vc;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.tableFooterView = [UIView new];
    self.tableView.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
    
    NSDictionary *commodity = self.m_dict[@"commodity"];
    NSDictionary *user = self.m_dict[@"user"];
    NSDictionary *contestant = self.m_dict[@"contestant"];
    
    
    NSArray *arr1 = @[@{ @"title": @"问诊单号", @"value":  commodity[@"no"]},
                      @{ @"title": @"患者", @"value":  user[@"name"]},
                      @{ @"title": @"手机号", @"value":  user[@"mobile"]},
                      @{ @"title": @"评论时间", @"value":  self.m_dict[@"created_at"]}];
    
    NSArray *arr2 = @[@{ @"title": @"接诊速度", @"value":  contestant[@"score"]},
                     @{ @"title": @"接诊态度", @"value":  contestant[@"score"]},
                     @{ @"title": @"诊疗效果", @"value":  contestant[@"score"]},
                     @{ @"title": @"综合评分", @"value":  contestant[@"score"]}];
    
    NSArray *arr3 = @[@{ @"title": self.m_dict[@"content"], @"value": @""}];
                      
    
    self.m_array = @[ arr1, arr2, arr3];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.m_array.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *arr = self.m_array[section];
    return arr.count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 2) {
        return @"评论内容";
    }
    return @"";
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==1) {
        return 15;
    }else if (section==2) {
        return 40;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    EvaluationDetailTableViewCell *cell = (EvaluationDetailTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"EvaluationDetailTableViewCellID" forIndexPath:indexPath];
    
    NSInteger section = [indexPath section];
    NSInteger row = [indexPath row];
    
    NSDictionary *dict = self.m_array[section][row];
    NSString *title = dict[@"title"];
    NSString *value = [NSString stringWithFormat:@"%@",dict[@"value"]];
    cell.textLabel.text = title;
    cell.detailTextLabel.text = value;
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
